public class Solution669 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode trimBST(TreeNode root, int low, int high) {
        if (root==null){
            return null;
        }
        if (root.val>=low && root.val<=high){
            root.left=trimBST(root.left,low,high);
            root.right=trimBST(root.right,low,high);
            return root;
        }else if (root.val<low){
            return trimBST(root.right,low,high);
        }else {
            return trimBST(root.left,low,high);
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution669().trimBST(new TreeNode(3,new TreeNode(0,null,new TreeNode(2,new TreeNode(1),null)),new TreeNode(4)),1,3).left.left.val);
    }
}
